package com.ymatou.iapi.userservice.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.login.service.LoginAuthCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymatou.iapi.userservice.parameter.PasswordResetRequestDtoBean;
import com.ymatou.iapi.userservice.parameter.req.CreateUserReq;
import com.ymatou.iapi.userservice.service.PasswordResetRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
/**
*重置用户登录密码Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_PasswordResetRequestDto{
	private static PasswordResetRequestDtoBean passwordresetrequestdtoBean;
	private static PasswordResetRequestDtoCall passwordresetrequestdtoCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("重置用户登录密码Test");
	}

	@Before
	public void caseUp() {
		passwordresetrequestdtoBean=new PasswordResetRequestDtoBean();
		passwordresetrequestdtoCall=new PasswordResetRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(passwordresetrequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_001() {
		Logger.start(true,"重置用户登录密码,成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid = urrc.getUserid();
			
			passwordresetrequestdtoBean.setUserId(uid);
			passwordresetrequestdtoBean.setNewPassword("abc123");
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
			
			Logger.verifyEquals("true", passwordresetrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("200", passwordresetrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			//验证登录密码是否更新成功
			LoginAuthCall logincall = JUserCallService.login(regbean.getLoginId(), "abc123", "App", regbean.getClientIp(),regbean.getDeviceId());
			Logger.verifyEquals("true", logincall.getString("Success"), "验证Success");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_002() {
		Logger.start(true,"userId空,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			//passwordresetrequestdtoBean.setUserId(uid);
			passwordresetrequestdtoBean.setNewPassword("abc123");
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
			
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("UserIdError", passwordresetrequestdtoCall.getString("Result"), "验证Result");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_003() {
		Logger.start(true,"NewPassword空,失败");
		try {
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			
			passwordresetrequestdtoBean.setUserId(uid);
			//passwordresetrequestdtoBean.setNewPassword("abc123");
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
			
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("NewPasswordEmpty", passwordresetrequestdtoCall.getString("Result"), "验证Result");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_004() {
		Logger.start(true,"uid不存在,失败");
		try {						
			passwordresetrequestdtoBean.setUserId(88888888);
			passwordresetrequestdtoBean.setNewPassword("abc123");
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
			
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("UserNotFind", passwordresetrequestdtoCall.getString("Result"), "验证Result");
			Logger.verifyEquals("用户不存在", passwordresetrequestdtoCall.getString("LastErrorMessage"), "验证LastErrorMessage");
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_005() {
		Logger.start(true,"密码小于6位,失败");
		try {	
			CreateUserReq cur = new CreateUserReq();
			cur = JUserCallService.initCreateUserBean(cur);
			Integer uid = JUserCallService.createUserCall(cur);
			passwordresetrequestdtoBean.setUserId(uid);
			passwordresetrequestdtoBean.setNewPassword("abc12");
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
			
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			Logger.verifyEquals("NewPasswordLenthLt6", passwordresetrequestdtoCall.getString("Result"), "验证Result");
			
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_PasswordResetRequestDto_006() {
		Logger.start(false,"重置用户登录密码和交易密码不能相同JIRACONN-17376");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			
			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token=registerResult.get("Token").getAsString();
			int uid = urrc.getUserid();
			JUserCallService.UpdateTradingPwd(uid, "654321a");
			passwordresetrequestdtoBean.setUserId(uid);
			passwordresetrequestdtoBean.setNewPassword("654321a");
			passwordresetrequestdtoCall.setData(passwordresetrequestdtoBean);
			passwordresetrequestdtoCall.callService();
			
			Logger.verifyEquals("false", passwordresetrequestdtoCall.getString("Success"), "验证Success");
			Logger.verifyEquals("400", passwordresetrequestdtoCall.getString("ResponseCode"), "验证ResponseCode");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}